package com.jhy.ws.storage;



import org.springframework.web.socket.WebSocketSession;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

public class WebSocketSessionStorage {
    /**
     * 保存已登录的会话session
     */
    public static ConcurrentHashMap<String, WebSocketSession> SESSION_MAP = new ConcurrentHashMap<>();

    /**
     * 统计在线人数 使用原子递增 若后期集群部署可引入 redis 的 incr 操作
     */
    public static AtomicInteger atomicInteger = new AtomicInteger(0);


    public static Integer incr() {
        return atomicInteger.incrementAndGet();
    }

    public static Integer decr() {
        return atomicInteger.decrementAndGet();
    }

    public static Integer getConnectCount() {
        return atomicInteger.get();
    }
}
